import Vue from "vue";
import Vuex from "vuex";
import persistedState from "vuex-persistedstate";
import getters from "./getters";

function rename(str) {
  return str.charAt(0) + str.slice(1);
}

const requireModules = require.context("./modules", false, /\.js$/);

let modules = {};

requireModules.keys().forEach((fileName) => {
  let config = requireModules(fileName);
  let apiName = rename(fileName.replace(/^\.\//, "").replace(/\.\w+$/, ""));
  modules[apiName] = config.default;
});

Vue.use(Vuex);

export default new Vuex.Store({
  modules,
  getters,
  plugins: [persistedState()]
});
